<#if po??>
package ${testPackage};

import java.util.List;

import javax.annotation.Resource;

import org.junit.Test;

<#list po.nonCommonFields as field>
<#if field.requireTypeImport && ! field.nullable>
import ${field.typeFullName};
</#if>
</#list>

import com.odianyun.db.mybatis.QueryParam;
import ${poPackage}.${po.name}PO;
import ${voPackage}.${po.name}VO;
import ${servicePackage}.${po.name}Service;
import ${basePackage}.test.base.TxTestBase;

public class ${po.name}ServiceTest extends TxTestBase {
    @Resource
    private ${po.name}Service service;

    @Test
    public void testAdd() throws Exception {
        print(doAdd());
    }
	
    @Test
    public void testUpdate() throws Exception {
        Long id = doAdd();
        ${po.name}PO po = service.getPOById(id);

        <#list po.nonCommonFields as field>
        <#if ! field.nullable && field.string>
        po.set${field.capitalizedName}("${field.name}-new");
        </#if>
        <#if ! field.nullable && field.number>
        po.set${field.capitalizedName}(${field.typeName}.valueOf(1));
        </#if>
        <#if ! field.nullable && field.date>
        po.set${field.capitalizedName}(new java.util.Date());
        </#if>
        </#list>

        service.updateWithTx(po);

        print(service.getPOById(id));
    }
	
    @Test
    public void testDelete() throws Exception {
        Long id = doAdd();
        service.deleteWithTx(id);
    }

    @Test
    public void testList() throws Exception {
        Long id = doAdd();
        List<${po.name}VO> list = service.list(new QueryParam().eq("id", id));

        print(list);
    }

    @Test
    public void testGet() throws Exception {
        Long id = doAdd();
        ${po.name}PO po = service.getPOById(id);

        print(po);
    }
	
    private Long doAdd() throws Exception {
        ${po.name}PO po = new ${po.name}PO();

        <#list po.nonCommonFields as field>
        <#if ! field.nullable && field.string>
        po.set${field.capitalizedName}("${field.name}");
        </#if>
        <#if ! field.nullable && field.number>
        po.set${field.capitalizedName}(${field.typeName}.valueOf(0));
        </#if>
        <#if ! field.nullable && field.date>
        po.set${field.capitalizedName}(new Date());
        </#if>
        </#list>

        return service.addWithTx(po);
    }
}
</#if>